//
//  Conference.m
//  Conference Track Management
//
//  Created by Jiang on 2018/10/22.
//  Copyright © 2018 jiang. All rights reserved.
//

#import "Conference.h"
#import "Session.h"
#import "SessionEndTime.h"
#import "NormalTalk.h"
#import "TraceNodeMaker.h"
#import "TraceNode.h"

@implementation Conference
- (instancetype)initWithMsession:(Session *)mSession afSession:(Session *)afSession talks:(NSArray<id <Talk>> *)talks{
    self = [super init];
    self.morningSessin = mSession;
    self.afternoonSessin = afSession;
    self.talks = talks;
    return self;
}
- (void)printAllTracks{
    TraceNodeMaker* m_maker = [[TraceNodeMaker alloc] initWithMin:self.morningSessin.minDuration
                                                              max:self.morningSessin.maxDuration
                                                            talks:self.talks];
    int count = 0;
    for (TraceNode *m_node in m_maker.traceNodes) {
            NSMutableSet *totalSet = [NSMutableSet setWithArray:self.talks];
            NSMutableSet *mSet = [NSMutableSet setWithArray:m_node.talks];
            [totalSet minusSet:mSet];
            NSArray *minusTalks = [totalSet allObjects];
            @autoreleasepool {
                TraceNodeMaker* af_maker = [[TraceNodeMaker alloc] initWithMin:self.afternoonSessin.minDuration
                                                                           max:self.afternoonSessin.maxDuration
                                                                         talks:minusTalks];
                for (TraceNode *af_node in af_maker.traceNodes) {
                    count++;
                    NSMutableString *track = [NSMutableString string];
                    [self.morningSessin makeTrackWithTalks:m_node.talks container:track];
                    [self.afternoonSessin makeTrackWithTalks:af_node.talks container:track];
                    printf("Track %d:\n%s",count,track.UTF8String);
                }
            }
    }
}
- (void)print{
    [self printAllTracks];
}
@end
